using System;
using System.Data.Entity.ModelConfiguration;
using System.Data.Common;
using System.Data.Entity;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using HISModels.Entities;

namespace HISModels.Mapping
{
	public class EmployeeMap : EntityTypeConfiguration<Employee>
	{
		public EmployeeMap()
		{
			// Primary Key
			this.HasKey(t => t.Id);

			// Properties
			this.Property(t => t.EmployeeNumber)
				.HasMaxLength(50);
				
			this.Property(t => t.SuperiorNumber)
				.HasMaxLength(50);
				
			this.Property(t => t.FirstName)
				.HasMaxLength(50);
				
			this.Property(t => t.LastName)
				.HasMaxLength(50);
				
			this.Property(t => t.TitleBeforeName)
				.HasMaxLength(50);
				
			this.Property(t => t.TitleAfterName)
				.HasMaxLength(50);
				
			// Table & Column Mappings
			this.ToTable("Employees");
			this.Property(t => t.Id).HasColumnName("Id");
			this.Property(t => t.EmployeeNumber).HasColumnName("EmployeeNumber");
			this.Property(t => t.SuperiorNumber).HasColumnName("SuperiorNumber");
			this.Property(t => t.FirstName).HasColumnName("FirstName");
			this.Property(t => t.DepartementId).HasColumnName("DepartementId");
			this.Property(t => t.Position).HasColumnName("Position");
			this.Property(t => t.HospitalUnitId).HasColumnName("HospitalUnitId");
			this.Property(t => t.LastName).HasColumnName("LastName");
			this.Property(t => t.TitleBeforeName).HasColumnName("TitleBeforeName");
			this.Property(t => t.TitleAfterName).HasColumnName("TitleAfterName");
			this.Property(t => t.RecordStatus).HasColumnName("RecordStatus");
			this.Property(t => t.GenderId).HasColumnName("GenderId");

			// Relationships
			this.HasOptional(t => t.Departement)
				.WithMany(t => t.Employees)
				.HasForeignKey(d => d.DepartementId);
				
			this.HasOptional(t => t.RefGender)
				.WithMany(t => t.Employees)
				.HasForeignKey(d => d.GenderId);
				
		}
	}
}

